home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / pibasy47.zip / ASYNCSEN.ASM < prev    next >
Assembly Source File  |  1987-11-11  |  3KB  |  50 lines

  1.          MOV     BX,[>Async_OBuffer_Head]   ;Get output queue head pointer
  2.          LES     DI,[>Async_OBuffer_Ptr]    ;Pick up output buffer address
  3.          ADD     DI,BX                      ;Position to current character
  4. ;
  5.          MOV     DX,BX                      ;Save previous head pointer
  6.          INC     BX                         ;Increment head pointer
  7.          CMP     BX,[>Async_OBuffer_Size]   ;See if past end of buffer
  8.          JLE     Send1                      ;Skip if not
  9.          XOR     BX,BX                      ;Wrap to start of buffer
  10. ;
  11. Send1:   CMP     BX,[>Async_OBuffer_Tail]   ;See if head collided with tail
  12.          JNE     Send4                      ;No -- buffer didn't fill up
  13. ;
  14.          MOV     CX,[>Async_Output_Delay]   ;Run delay loop and see if buffer drains
  15. ;
  16. Send2:   PUSH    CX                         ;Save milleseconds to go
  17.          MOV     CX,[>Async_OneMSDelay]     ;Get delay loop value for 1 ms
  18. ;
  19. Send3:   LOOP    Send3                      ;Tight loop for 1 ms delay
  20. ;
  21.          POP     CX                         ;Get back millesecond count
  22. ;
  23.          CMP     BX,[>Async_OBuffer_Tail]   ;See if buffer drained yet
  24.          JNE     Send4                      ;Yes -- OK, stop delay loop.
  25. ;
  26.          LOOP    Send2                      ;Decrement millesecond count and loop
  27. ;
  28.          MOV     BYTE [>Async_OBuffer_Overflow],1 ;Indicate output buffer overflow
  29.          JMP     Send5                      ;Skip updating head pointers
  30. ;
  31. Send4:   MOV     [>Async_OBuffer_Head],BX   ;Save updated head pointer
  32.          MOV     AL,[BP+<C]                 ;Pick up character to send
  33.      ES: MOV     [DI],AL                    ;Place character in output buffer
  34. ;
  35.          MOV     AX,[>Async_OBuffer_Used]   ;Get buffer use count
  36.          INC     AX                         ;Increment buffer use count
  37.          MOV     [>Async_OBuffer_Used],AX   ;Save new count
  38.          CMP     AX,[>Async_MaxOBufferUsed] ;See if larger than ever before
  39.          JLE     Send5                      ;Skip if not
  40.          MOV     [>Async_MaxOBufferUsed],AX ;Save new maximum usage
  41. ;
  42. Send5:   MOV     DX,[>Async_Uart_IER]       ;Get interrupt enable register
  43.          IN      AL,DX                      ;Check contents of IER
  44.          TEST    AL,2                       ;See if write interrupt enabled
  45.          JNZ     Send6                      ;Skip if so
  46.          OR      AL,2                       ;Else enable write interrupts ...
  47.          OUT     DX,AL                      ;... by rewriting IER contents
  48. ;
  49. Send6:
  50.